<?php

namespace app\test514\controller;

use think\Controller;

class Common extends Controller
{
    /**
     * 无限级分类
     *Method treelevel
     * @param array $data
     * @param int $pid
     * @param string $html
     * @param int $level
     *user:大飞
     *time:2021/5/18 21:14
     */
    //无限极分类
    public function get_tree_list($data,$pid=0,$html="--",$level=1){
        //定义静态空数组
        static $arr = [];

        //循环权限的数据
        foreach ($data as $v){
            //判断pid 是否等于$pid 等于则为顶级
            if($v['pid'] == $pid){
                $v['html'] = str_repeat($html,$level);
                $v['level'] = $level+1;
                $arr[] = $v;

                $this->get_tree_list($data,$v['id'],$html,$v['level']);
            }
        }
        return $arr;
    }

//        static $arr = [];
//        //循环传过来的内容
//        foreach ($data as $v)
//        {
//            if ($pid == $v['pid'])
//            {
//                //第一级4个-
//                $v['html']=str_repeat($html,$level*2);
//                //层级数
//                $v['level'] = $level +1;
//                $arr[] = $v;
//                $this->treelevel($data,$v['pid'],$html,$v['level']);
//            }
//        }
//        return $arr;

}
